# import datetime
# Usertime=0
# def log(f):
#     def time(*args,**kw):
#         global Usertime
#         Starttime=datetime.datetime.now()
#         print(datetime.datetime.now())
#         f(*args,**kw)
#         Overtime=datetime.datetime.now()
#         print(datetime.datetime.now())
#         Usetime=Overtime-Starttime
#         print('该函数执行耗时%s'%Usetime)
#     return time
# @log
# def func():
#     s = 0
#     for i in range(100000):
#         s += i
#     print(s)
# func()

import time #引入模块time
def metric(fn): #定义metric函数
    def cost(*args,**kw): #定义一个花费时间函数
        start_time = time.time()
        fn(*args, **kw) #执行fn函数
        end_time = time.time()
        print('耗时：{:.4f}s'.format(end_time-start_time)) #花费时间等于结束时间-开始时间
    return cost
@metric
def func():
    s = 0
    for i in range(100000):
        s += i
    print(s)
func()